<!-- HTML header for doxygen 1.8.20-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=9"/>
	<meta name="generator" content="Doxygen 1.9.4"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>Raspberry Pi Pico SDK: hardware_flash</title>
	<!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="dynsections.js"></script>
	<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
	<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
	<link href="doxygen.css" rel="stylesheet" type="text/css" />
	<link href="normalise.css" rel="stylesheet" type="text/css"/>
<link href="main.css" rel="stylesheet" type="text/css"/>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
	<div class="navigation-mobile">
		<div class="logo--mobile">
			<a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
		</div>
		<div class="navigation-toggle">
			<span class="line-1"></span>
			<span class="line-2">
				<p>Menu Toggle</p>
			</span>
			<span class="line-3"></span>
		</div>
	</div>
	<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
		<div class="logo">
			<a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
			<span style="display: inline-block; margin-top: 10px;">
				v2.1.0
			</span>
		</div>
		<div class="navigation-footer">
			<img src="logo-mobile.svg" alt="Raspberry Pi">
			<a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
		</div>
<!-- 		<div class="search">
			<form>
				<input type="search" name="search" id="search" placeholder="Search">
				<input type="submit" value="Search">
			</form>
		</div> -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('group__hardware__flash.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">hardware_flash<div class="ingroups"><a class="el" href="group__hardware.html">Hardware APIs</a></div></div></div>
</div><!--header-->
<div class="contents">

<p>Low level flash programming and erase API.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga5b88461b126b1c226121146c87d5abe2"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__flash.html#ga5b88461b126b1c226121146c87d5abe2">flash_range_erase</a> (uint32_t flash_offs, size_t count)</td></tr>
<tr class="memdesc:ga5b88461b126b1c226121146c87d5abe2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Erase areas of flash.  <a href="group__hardware__flash.html#ga5b88461b126b1c226121146c87d5abe2">More...</a><br /></td></tr>
<tr class="separator:ga5b88461b126b1c226121146c87d5abe2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga345513fba0951661d012fa20a6441c5f"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__flash.html#ga345513fba0951661d012fa20a6441c5f">flash_range_program</a> (uint32_t flash_offs, const uint8_t *data, size_t count)</td></tr>
<tr class="memdesc:ga345513fba0951661d012fa20a6441c5f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Program flash.  <a href="group__hardware__flash.html#ga345513fba0951661d012fa20a6441c5f">More...</a><br /></td></tr>
<tr class="separator:ga345513fba0951661d012fa20a6441c5f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga5c6452005ad28f1e444698b0b97194d2"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__flash.html#ga5c6452005ad28f1e444698b0b97194d2">flash_get_unique_id</a> (uint8_t *id_out)</td></tr>
<tr class="memdesc:ga5c6452005ad28f1e444698b0b97194d2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get flash unique 64 bit identifier.  <a href="group__hardware__flash.html#ga5c6452005ad28f1e444698b0b97194d2">More...</a><br /></td></tr>
<tr class="separator:ga5c6452005ad28f1e444698b0b97194d2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga9e352de7ea62ffebc579f6449b5b44d3"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__flash.html#ga9e352de7ea62ffebc579f6449b5b44d3">flash_do_cmd</a> (const uint8_t *txbuf, uint8_t *rxbuf, size_t count)</td></tr>
<tr class="memdesc:ga9e352de7ea62ffebc579f6449b5b44d3"><td class="mdescLeft">&#160;</td><td class="mdescRight">Execute bidirectional flash command.  <a href="group__hardware__flash.html#ga9e352de7ea62ffebc579f6449b5b44d3">More...</a><br /></td></tr>
<tr class="separator:ga9e352de7ea62ffebc579f6449b5b44d3"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p >Low level flash programming and erase API. </p>
<p >Note these functions are <em>unsafe</em> if you are using both cores, and the other is executing from flash concurrently with the operation. In this case, you must perform your own synchronisation to make sure that no XIP accesses take place during flash programming. One option is to use the <a class="el" href="group__multicore__lockout.html">lockout</a> functions.</p>
<p >Likewise they are <em>unsafe</em> if you have interrupt handlers or an interrupt vector table in flash, so you must disable interrupts before calling in this case.</p>
<p >If PICO_NO_FLASH=1 is not defined (i.e. if the program is built to run from flash) then these functions will make a static copy of the second stage bootloader in SRAM, and use this to reenter execute-in-place mode after programming or erasing flash, so that they can safely be called from flash-resident code.</p>
<h2><a class="anchor" id="flash_example"></a>
Example</h2>
<div class="fragment"><div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="stdio_8h.html">stdio.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="stdlib_8h.html">stdlib.h</a>&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="stdlib_8h.html">pico/stdlib.h</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="pico__flash_2include_2pico_2flash_8h.html">pico/flash.h</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="hardware__flash_2include_2hardware_2flash_8h.html">hardware/flash.h</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// We&#39;re going to erase and reprogram a region 256k from the start of flash.</span></div>
<div class="line"><span class="comment">// Once done, we can access this at XIP_BASE + 256k.</span></div>
<div class="line"><span class="preprocessor">#define FLASH_TARGET_OFFSET (256 * 1024)</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">const</span> uint8_t *flash_target_contents = (<span class="keyword">const</span> uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET);</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> print_buf(<span class="keyword">const</span> uint8_t *buf, <span class="keywordtype">size_t</span> len) {</div>
<div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; len; ++i) {</div>
<div class="line">        printf(<span class="stringliteral">&quot;%02x&quot;</span>, buf[i]);</div>
<div class="line">        <span class="keywordflow">if</span> (i % 16 == 15)</div>
<div class="line">            printf(<span class="stringliteral">&quot;\n&quot;</span>);</div>
<div class="line">        <span class="keywordflow">else</span></div>
<div class="line">            printf(<span class="stringliteral">&quot; &quot;</span>);</div>
<div class="line">    }</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">// This function will be called when it&#39;s safe to call flash_range_erase</span></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> call_flash_range_erase(<span class="keywordtype">void</span> *param) {</div>
<div class="line">    uint32_t offset = (uint32_t)param;</div>
<div class="line">    <a class="code hl_function" href="group__hardware__flash.html#ga5b88461b126b1c226121146c87d5abe2">flash_range_erase</a>(offset, FLASH_SECTOR_SIZE);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">// This function will be called when it&#39;s safe to call flash_range_program</span></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> call_flash_range_program(<span class="keywordtype">void</span> *param) {</div>
<div class="line">    uint32_t offset = ((uintptr_t*)param)[0];</div>
<div class="line">    <span class="keyword">const</span> uint8_t *data = (<span class="keyword">const</span> uint8_t *)((uintptr_t*)param)[1];</div>
<div class="line">    <a class="code hl_function" href="group__hardware__flash.html#ga345513fba0951661d012fa20a6441c5f">flash_range_program</a>(offset, data, FLASH_PAGE_SIZE);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line">    <a class="code hl_function" href="group__pico__stdio.html#ga0e604311fb226dae91ff4eb17a19d67a">stdio_init_all</a>();</div>
<div class="line">    uint8_t random_data[FLASH_PAGE_SIZE];</div>
<div class="line">    <span class="keywordflow">for</span> (uint i = 0; i &lt; FLASH_PAGE_SIZE; ++i)</div>
<div class="line">        random_data[i] = rand() &gt;&gt; 16;</div>
<div class="line"> </div>
<div class="line">    printf(<span class="stringliteral">&quot;Generated random data:\n&quot;</span>);</div>
<div class="line">    print_buf(random_data, FLASH_PAGE_SIZE);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// Note that a whole number of sectors must be erased at a time.</span></div>
<div class="line">    printf(<span class="stringliteral">&quot;\nErasing target region...\n&quot;</span>);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// Flash is &quot;execute in place&quot; and so will be in use when any code that is stored in flash runs, e.g. an interrupt handler</span></div>
<div class="line">    <span class="comment">// or code running on a different core.</span></div>
<div class="line">    <span class="comment">// Calling flash_range_erase or flash_range_program at the same time as flash is running code would cause a crash.</span></div>
<div class="line">    <span class="comment">// flash_safe_execute disables interrupts and tries to cooperate with the other core to ensure flash is not in use</span></div>
<div class="line">    <span class="comment">// See the documentation for flash_safe_execute and its assumptions and limitations</span></div>
<div class="line">    <span class="keywordtype">int</span> rc = <a class="code hl_function" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a>(call_flash_range_erase, (<span class="keywordtype">void</span>*)FLASH_TARGET_OFFSET, UINT32_MAX);</div>
<div class="line">    hard_assert(rc == <a class="code hl_enumvalue" href="group__pico__base.html#ggaddcb20bc9a61ceff479aa87369a862aaa9b50bcb755cf2e8295de9ffa52b252fd">PICO_OK</a>);</div>
<div class="line"> </div>
<div class="line">    printf(<span class="stringliteral">&quot;Done. Read back target region:\n&quot;</span>);</div>
<div class="line">    print_buf(flash_target_contents, FLASH_PAGE_SIZE);</div>
<div class="line"> </div>
<div class="line">    printf(<span class="stringliteral">&quot;\nProgramming target region...\n&quot;</span>);</div>
<div class="line">    uintptr_t params[] = { FLASH_TARGET_OFFSET, (uintptr_t)random_data};</div>
<div class="line">    rc = <a class="code hl_function" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a>(call_flash_range_program, params, UINT32_MAX);</div>
<div class="line">    hard_assert(rc == <a class="code hl_enumvalue" href="group__pico__base.html#ggaddcb20bc9a61ceff479aa87369a862aaa9b50bcb755cf2e8295de9ffa52b252fd">PICO_OK</a>);</div>
<div class="line">    printf(<span class="stringliteral">&quot;Done. Read back target region:\n&quot;</span>);</div>
<div class="line">    print_buf(flash_target_contents, FLASH_PAGE_SIZE);</div>
<div class="line"> </div>
<div class="line">    <span class="keywordtype">bool</span> mismatch = <span class="keyword">false</span>;</div>
<div class="line">    <span class="keywordflow">for</span> (uint i = 0; i &lt; FLASH_PAGE_SIZE; ++i) {</div>
<div class="line">        <span class="keywordflow">if</span> (random_data[i] != flash_target_contents[i])</div>
<div class="line">            mismatch = <span class="keyword">true</span>;</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">if</span> (mismatch)</div>
<div class="line">        printf(<span class="stringliteral">&quot;Programming failed!\n&quot;</span>);</div>
<div class="line">    <span class="keywordflow">else</span></div>
<div class="line">        printf(<span class="stringliteral">&quot;Programming successful!\n&quot;</span>);</div>
<div class="line">}</div>
<div class="ttc" id="agroup__hardware__flash_html_ga345513fba0951661d012fa20a6441c5f"><div class="ttname"><a href="group__hardware__flash.html#ga345513fba0951661d012fa20a6441c5f">flash_range_program</a></div><div class="ttdeci">void __no_inline_not_in_flash_func() flash_range_program(uint32_t flash_offs, const uint8_t *data, size_t count)</div><div class="ttdoc">Program flash.</div><div class="ttdef"><b>Definition:</b> flash.c:151</div></div>
<div class="ttc" id="agroup__hardware__flash_html_ga5b88461b126b1c226121146c87d5abe2"><div class="ttname"><a href="group__hardware__flash.html#ga5b88461b126b1c226121146c87d5abe2">flash_range_erase</a></div><div class="ttdeci">void __no_inline_not_in_flash_func() flash_range_erase(uint32_t flash_offs, size_t count)</div><div class="ttdoc">Erase areas of flash.</div><div class="ttdef"><b>Definition:</b> flash.c:114</div></div>
<div class="ttc" id="agroup__pico__base_html_ggaddcb20bc9a61ceff479aa87369a862aaa9b50bcb755cf2e8295de9ffa52b252fd"><div class="ttname"><a href="group__pico__base.html#ggaddcb20bc9a61ceff479aa87369a862aaa9b50bcb755cf2e8295de9ffa52b252fd">PICO_OK</a></div><div class="ttdeci">@ PICO_OK</div><div class="ttdoc">No error; the operation succeeded.</div><div class="ttdef"><b>Definition:</b> error.h:23</div></div>
<div class="ttc" id="agroup__pico__flash_html_ga679076dc10c5beb73d5f1abdb52d6735"><div class="ttname"><a href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a></div><div class="ttdeci">int flash_safe_execute(void(*func)(void *), void *param, uint32_t enter_exit_timeout_ms)</div><div class="ttdoc">Execute a function with IRQs disabled and with the other core also not executing/reading flash.</div><div class="ttdef"><b>Definition:</b> flash.c:75</div></div>
<div class="ttc" id="agroup__pico__stdio_html_ga0e604311fb226dae91ff4eb17a19d67a"><div class="ttname"><a href="group__pico__stdio.html#ga0e604311fb226dae91ff4eb17a19d67a">stdio_init_all</a></div><div class="ttdeci">bool stdio_init_all(void)</div><div class="ttdoc">Initialize all of the present standard stdio types that are linked into the binary.</div><div class="ttdef"><b>Definition:</b> stdio.c:200</div></div>
<div class="ttc" id="ahardware__flash_2include_2hardware_2flash_8h_html"><div class="ttname"><a href="hardware__flash_2include_2hardware_2flash_8h.html">flash.h</a></div></div>
<div class="ttc" id="apico__flash_2include_2pico_2flash_8h_html"><div class="ttname"><a href="pico__flash_2include_2pico_2flash_8h.html">flash.h</a></div></div>
<div class="ttc" id="astdio_8h_html"><div class="ttname"><a href="stdio_8h.html">stdio.h</a></div></div>
<div class="ttc" id="astdlib_8h_html"><div class="ttname"><a href="stdlib_8h.html">stdlib.h</a></div></div>
</div><!-- fragment --> <h2 class="groupheader">Function Documentation</h2>
<a id="ga9e352de7ea62ffebc579f6449b5b44d3" name="ga9e352de7ea62ffebc579f6449b5b44d3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga9e352de7ea62ffebc579f6449b5b44d3">&#9670;&nbsp;</a></span>flash_do_cmd()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void flash_do_cmd </td>
          <td>(</td>
          <td class="paramtype">const uint8_t *&#160;</td>
          <td class="paramname"><em>txbuf</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint8_t *&#160;</td>
          <td class="paramname"><em>rxbuf</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>count</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Execute bidirectional flash command. </p>
<p >Low-level function to execute a serial command on a flash device attached to the QSPI interface. Bytes are simultaneously transmitted and received from txbuf and to rxbuf. Therefore, both buffers must be the same length, count, which is the length of the overall transaction. This is useful for reading metadata from the flash chip, such as device ID or SFDP parameters.</p>
<p >The XIP cache is flushed following each command, in case flash state has been modified. Like other hardware_flash functions, the flash is not accessible for execute-in-place transfers whilst the command is in progress, so entering a flash-resident interrupt handler or executing flash code on the second core concurrently will be fatal. To avoid these pitfalls it is recommended that this function only be used to extract flash metadata during startup, before the main application begins to run: see the implementation of pico_get_unique_id() for an example of this.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">txbuf</td><td>Pointer to a byte buffer which will be transmitted to the flash </td></tr>
    <tr><td class="paramname">rxbuf</td><td>Pointer to a byte buffer where data received from the flash will be written. txbuf and rxbuf may be the same buffer. </td></tr>
    <tr><td class="paramname">count</td><td>Length in bytes of txbuf and of rxbuf </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ga5c6452005ad28f1e444698b0b97194d2" name="ga5c6452005ad28f1e444698b0b97194d2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5c6452005ad28f1e444698b0b97194d2">&#9670;&nbsp;</a></span>flash_get_unique_id()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void flash_get_unique_id </td>
          <td>(</td>
          <td class="paramtype">uint8_t *&#160;</td>
          <td class="paramname"><em>id_out</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get flash unique 64 bit identifier. </p>
<p >Use a standard 4Bh RUID instruction to retrieve the 64 bit unique identifier from a flash device attached to the QSPI interface. Since there is a 1:1 association between the MCU and this flash, this also serves as a unique identifier for the board.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">id_out</td><td>Pointer to an 8-byte buffer to which the ID will be written </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ga5b88461b126b1c226121146c87d5abe2" name="ga5b88461b126b1c226121146c87d5abe2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5b88461b126b1c226121146c87d5abe2">&#9670;&nbsp;</a></span>flash_range_erase()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void flash_range_erase </td>
          <td>(</td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>flash_offs</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>count</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Erase areas of flash. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">flash_offs</td><td>Offset into flash, in bytes, to start the erase. Must be aligned to a 4096-byte flash sector. </td></tr>
    <tr><td class="paramname">count</td><td>Number of bytes to be erased. Must be a multiple of 4096 bytes (one sector).</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>Erasing a flash sector sets all the bits in all the pages in that sector to one. You can then "program" flash pages in the sector to turn some of the bits to zero. Once a bit is set to zero it can only be changed back to one by erasing the whole sector again. </dd></dl>

</div>
</div>
<a id="ga345513fba0951661d012fa20a6441c5f" name="ga345513fba0951661d012fa20a6441c5f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga345513fba0951661d012fa20a6441c5f">&#9670;&nbsp;</a></span>flash_range_program()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void flash_range_program </td>
          <td>(</td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>flash_offs</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const uint8_t *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>count</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Program flash. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">flash_offs</td><td>Flash address of the first byte to be programmed. Must be aligned to a 256-byte flash page. </td></tr>
    <tr><td class="paramname">data</td><td>Pointer to the data to program into flash </td></tr>
    <tr><td class="paramname">count</td><td>Number of bytes to program. Must be a multiple of 256 bytes (one page).</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>: Programming a flash page effectively changes some of the bits from one to zero. The only way to change a zero bit back to one is to "erase" the whole sector that the page resides in. So you may need to make sure you have called flash_range_erase before calling flash_range_program. </dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->

	<script src="main.js"></script>
</body>
</html>